<template>
  <view class="service-section">
    <view class="service-section__header">
      <text class="service-section__title">{{ title }}</text>
      <text class="service-section__more" v-if="showMore" @click="onMoreClick">{{ moreText }}</text>
    </view>
    <view class="service-items">
      <view 
        v-for="(item, index) in services" 
        :key="index" 
        class="service-item"
        @click="onServiceClick(item, index)"
      >
        <view class="service-item__top">
          <image :src="item.image" mode="aspectFill" class="service-item__image" />
          <view 
            v-if="item.tag || item.hot" 
            class="service-item__tag"
            :style="{ backgroundColor: item.tagColor || (item.hot ? '#ff6b6b' : '#07c160') }"
          >
            {{ item.tag || (item.hot ? '热门' : '') }}
          </view>
        </view>
        <view class="service-item__title">{{ item.title }}</view>
        <view class="service-item__info">
          <text class="service-item__price">{{ item.price }}</text>
          <text class="service-item__sales">{{ item.sales }}人已下单</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue';

const props = defineProps({
  title: {
    type: String,
    default: '服务列表'
  },
  services: {
    type: Array,
    default: () => []
  },
  showMore: {
    type: Boolean,
    default: true
  },
  moreText: {
    type: String,
    default: '查看更多 >'
  }
});

const emit = defineEmits(['service-click', 'more-click']);

const onServiceClick = (service, index) => {
  emit('service-click', { service, index });
};

const onMoreClick = () => {
  emit('more-click');
};
</script>

<style lang="scss" scoped>
.service-section {
  margin: 0 10px 15px;
  background-color: #fff;
  border-radius: 8px;
  padding: 15px;
  
  &__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
  }
  
  &__title {
    font-size: 16px;
    font-weight: bold;
    color: #333;
  }
  
  &__more {
    font-size: 12px;
    color: #999;
  }
}

.service-items {
  display: flex;
  flex-wrap: wrap;
  margin: 0 -5px;
}

.service-item {
  width: calc(50% - 10px);
  margin: 0 5px 15px;
  
  &__top {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 8px;
  }
  
  &__image {
    width: 100%;
    height: 100px;
    display: block;
  }
  
  &__tag {
    position: absolute;
    top: 5px;
    right: 5px;
    background-color: #ff6b6b;
    color: #fff;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
  }
  
  &__title {
    font-size: 14px;
    color: #333;
    margin-bottom: 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    height: 38px;
  }
  
  &__info {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  
  &__price {
    font-size: 14px;
    font-weight: bold;
    color: #ff6b6b;
  }
  
  &__sales {
    font-size: 12px;
    color: #999;
  }
}
</style>
